package com.wing.web.config;

import com.wing.web.common.interceptor.InterfaceInterceptor;
import com.wing.web.common.xss.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

/**
 * Filter配置
 *
 * @author
 */
@Configuration
public class FilterConfig {

//	/**
//	 * 登录过滤器，处理session超时。
//	 * @return
//	 */
//	@Bean
//	public FilterRegistrationBean loginFilterRegistration() {
//		FilterRegistrationBean registration = new FilterRegistrationBean();
//		registration.setFilter(new LoginFilter());
//		// 要过滤的url，可多个。
//		List<String> urlList = new ArrayList<>();
//		urlList.add("/user/**");
//		urlList.add("/**");
//		registration.setUrlPatterns(urlList);
//		return registration;
//	}

    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        //排除不过滤的路径,多个用逗号隔开
        // registration.addInitParameter("exclusions","/admin/rule,/admin/var");
        registration.setName("xssFilter");
        registration.setOrder(Integer.MAX_VALUE);
        return registration;
    }

    @Bean
    public FilterRegistrationBean urlFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new InterfaceInterceptor());
        registration.addUrlPatterns("/**");
        //排除不过滤的路径,多个用逗号隔开
        // registration.addInitParameter("exclusions","/admin/rule,/admin/var");
        registration.setName("urlFilter");
        registration.setOrder(Integer.MIN_VALUE);
        return registration;
    }
}
